function [loc,vel]=orb2state(ra,per,semi,e,inc,t,u)
%[loc,vel]=orb2state(ra,per,semi,e,inc,t,u)
%
% ra  = right ascension of ascending node=Ω
% per = argument of perigee=ω
% semi= semi major axis=a
% e   = eccentricity
% inc = inclination=i
% t   = true anomaly
%
% Return [loc,vel] in x,y,z form. 
p=semi*(1-(e^2));

% Convert Angles to radians for trig. func.
ra=deg2rad(ra);
per=deg2rad(per);
inc=deg2rad(inc);

loc(1)=p * (cos(ra)*cos(per+t) - sin(ra)*cos(inc)*sin(per+t));
loc(2)=p * (sin(ra)*cos(per+t) - cos(ra)*cos(inc)*sin(per+t));
loc(3)=p * sin(inc)*sin(per+t);

vel(1)=-sqrt(u/p)*(cos(ra)*(sin(per+t)+e*sin(per))+sin(ra)*cos(inc)*(cos(per+t)+e*cos(per)));
vel(2)=-sqrt(u/p)*(sin(ra)*(sin(per+t)+e*sin(per))-cos(ra)*cos(inc)*(cos(per+t)+e*cos(per)));
vel(3)=-sqrt(u/p)*(sin(inc)*(cos(per+t)+e*sin(per)));


end